<?php
	$arParams = Zend_Registry::isRegistered('searchBoxParams') ? Zend_Registry::get('searchBoxParams') : array();
	$arParams = array_replace(array(
		'sale_type' => OBJECT_SALE,
		'country' => 0,
		'region' => 0,
		'city' => 0,
		'location' => 0,
		'object_type' => 0,
		'object_price_low' => 0,
		'object_price_high' => 0,
		'object_see_distance' => 0,
		'object_air_distance' => 0,
		'object_year' => 0,
		'object_area_low' => 0,
		'object_area_high' => 0,
		'object_bedrooms_low' => 0,
		'object_bedrooms_high' => 0,
		'SwimmingPool' => 0,
		'Security' => 0,
		'Parking' => 0,
		'object_id' => 0,
		'page' => 1,
	), $arParams);
	
	$arCountries = array(0 => array('Name' => _('Выберите страну'))) + Obj_Country::getCountries(true);
	$arRegions = array(0 => array('Name' => _('Выберите регион'))) + Obj_Region::getRegions($arParams['country'], true);
	
	$arCities = array(0 => array('RegionID' => 0, 'Name' => _('Выберите город'))) + Obj_City::getCountryCities($arParams['country'], true);
	
	$arLocations = array(0 => array('Name' => _('Выберите район'))) + Obj_Location::getLocations($arParams['city'], true);
	$arObjectTypes = array(0 => array('Name' => _('Все'))) + Obj_ObjectType::getObjectTypes(true);
	$arObjectYears = array(0 => array('Name' => _('Год постройки'))) + Obj_Object::getObjectYears();
	$arObjectSeeDistance = array(
		0 => _('Расстояние до моря'),
		50 => _('&lt; 50м'),
		100 => _('50 - 100м'),
		200 => _('100 - 200м'),
		500 => _('200 - 500м'),
		1000 => _('500м - 1км'),
		2000 => _('1км - 2км'),
		5000 => _('2км - 5км'),
		10000 => _('5км - 10км'),
		999999999 => _('&gt 10км'),
	);
	
	$arObjectAirDistance = array(
		0 => _('Расстояние до аэропорта'),
		10 => _('&lt; 10км'),
		20 => _('10км - 20км'),
		30 => _('20км - 30км'),
		40 => _('30км - 40км'),
		50 => _('40км - 50км'),
		60 => _('50км - 60км'),
		80 => _('60км - 80км'),
		10000 => _('&gt; 80км'),
	);
	
?>
<form action="<?=HTTP_HOST?>/search/" method="post" id="search-objects-form-hidden">
</form>
<form action="<?=HTTP_HOST?>/search/" method="post" id="search-objects-form">
	<input type="hidden" name="sale_type" value="<?=$arParams['sale_type']?>" />
	<input type="hidden" name="page" value="<?=$arParams['page']?>" />
	<div id="filter_d">
		<div class="filter_block" style="z-index: 250;">
			<div class="search_type">
				<a<?=($arParams['sale_type'] == OBJECT_SALE) ? ' class="active"' : ''?> rel="<?=OBJECT_SALE?>" href="javascript:;"><?=$this->translate('Продажа')?></a> | <a<?=($arParams['sale_type'] == OBJECT_RENT) ? ' class="active"' : ''?> rel="<?=OBJECT_RENT?>" href="javascript:;"><?=$this->translate('Аренда')?></a> | <a<?=($arParams['sale_type'] == OBJECT_INVESTMENT_PROJECT) ? ' class="active"' : ''?> rel="<?=OBJECT_INVESTMENT_PROJECT?>" href="javascript:;"><?=$this->translate('Инвестпроект')?></a>
			</div>
			<select name="country" onchange="sb_changeCountry(this);">
			<?php
				foreach ($arCountries as $k => $v) {
					echo '<option value="'.$k.'"'.($k == $arParams['country'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
				} 
			?>
			</select>
			<select name="region" onchange="sb_changeRegion(this);">
			<?php
				foreach ($arRegions as $k => $v) {
					echo '<option value="'.$k.'"'.($k == $arParams['region'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
				} 
			?>
			</select>
		</div>
		<div class="filter_block" style="z-index: 250;">
			<span class="sale_fld" style="bottom: 1px;"><?=$this->translate('Расположение')?></span>
			<select name="city" onchange="sb_changeCity(this);">
			<?php
				$regid = -1;
				$optgroup = false;
				foreach ($arCities as $k => $v) {
					if ($v['RegionID'] != $regid) {
						$regid = $v['RegionID'];
						if ($optgroup != false) {
							echo '</optgroup>';
							$optgroup = false;
						}
						if ($v['RegionID'] == 0) {
							//just add the option
							echo '<option value="'.$k.'"'.($k == $arParams['city'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
						}
						else {
							$optgroup = true;
							echo '<optgroup label="'.$v['RName'].'" class="'.$v['RegionID'].'">';
							echo '<option value="'.$k.'"'.($k == $arParams['city'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
						}
					}
					else {
						echo '<option value="'.$k.'"'.($k == $arParams['city'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
					}
				}
				if ($optgroup != false) {
					echo '</optgroup>';
				}
			?>
			</select>
			<select name="location">
			<?php
				foreach ($arLocations as $k => $v) {
					echo '<option value="'.$k.'"'.($k == $arParams['location'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
				} 
			?>
			</select>
		</div>
		<div class="filter_block" style="z-index: 250;">
			<span class="sale_fld" style="bottom: 1px;"><?=_('Тип объекта')?></span>
			<select name="object_type" style="margin-bottom: 4px;">
			<?php
				foreach ($arObjectTypes as $k => $v) {
					echo '<option value="'.$k.'"'.($k == $arParams['object_type'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
				} 
			?>
			</select>
			<span class="white_bold_text" id="show_more_filters" style="bottom: 3px;">+ <?=_('Расширить поиск')?></span>
		</div>
		<div class="filter_block" style="width: 230px !important; right: 2px;">
			<table style="padding: 0px; margin: 0px; position: relative; float: left; bottom: 6px; width: 245px; border: 0px none">
				<tr>
					<td colspan="2">
						<span style="position: relative; float: left; width: 100%; height: 100%; top:2px;"><?=$this->translate('Ценовой диапазон')?></span>
					</td>
				</tr>
				<tr>
					<td style="width: 97px; vertical-align: top;">
						<div class="filter_block_div" style=" margin-top: 1px">
							<input type="text" name="object_price_low" value="<?=$arParams['object_price_low'] > 0 ? $arParams['object_price_low'] : ''?>" maxlength="6" class="filter_block_field"/>
						</div>
						<div class="dash_separator" style=" margin-top: 2px"> - </div>
						<div class="filter_block_div" style=" margin: 1px 0px 0px 1px">
							<input type="text" name="object_price_high" maxlength="8" value="<?=$arParams['object_price_high'] > 0 ? $arParams['object_price_high'] : ''?>" class="filter_block_field"/>
						</div>
					</td>
					<td>
						<input type="submit" value=""/>
					</td>
				</tr>
			</table>
		</div>
		<div id="extended_filter">
			<div class="filter_block_ex ex" id="bottom_sel">
				<select name="object_see_distance">
				<?php
					foreach ($arObjectSeeDistance as $k => $v) {
						echo '<option value="'.$k.'"'.($k == $arParams['object_see_distance'] ? ' selected="selected"' : '').'>'.$v.'</option>';
					} 
				?>
				</select>
				<select name="object_air_distance">
				<?php
					foreach ($arObjectAirDistance as $k => $v) {
						echo '<option value="'.$k.'"'.($k == $arParams['object_air_distance'] ? ' selected="selected"' : '').'>'.$v.'</option>';
					} 
				?>
				</select>
				<select name="object_year">
				<?php
					foreach ($arObjectYears as $k => $v) {
						echo '<option value="'.$k.'"'.($k == $arParams['object_year'] ? ' selected="selected"' : '').'>'.$v['Name'].'</option>';
					} 
				?>
				</select>
			</div>
			<div class="filter_block_ex ex" style="padding-top: 0px;">
				<div style="position: relative; float: left; width: 202px; height: 20px; padding: 0; margin: 0px">
					<span style="position: relative; float: left; width: auto;top: 3px"><?=$this->translate('Площадь')?></span> 
					<div style="psition: relative; float: right; width: 103px; bottom: 7px;">
						<div class="filter_block_div">
							<input type="text" name="object_area_low" value="<?=$arParams['object_area_low'] > 0 ? $arParams['object_area_low'] : ''?>" maxlength="6" class="filter_block_field"/>
						</div> 
						<div class="dash_separator"> - </div> 
						<div class="filter_block_div">
							<input type="text" name="object_area_high" value="<?=$arParams['object_area_high'] > 0 ? $arParams['object_area_high'] : ''?>" maxlength="6" class="filter_block_field"/>
						</div>
					</div>
				</div>
				<div style="possition: relative; float: left; width: 100%; height: auto; margin: 3px 0px 4px 0px;"><?=$this->translate('Количество спален')?></div>
				<div style="position: relative; float: left; width: 100%; height: auto">
					<div class="filter_block_div">
						<input type="text" name="object_bedrooms_low" value="<?=$arParams['object_bedrooms_low'] > 0 ? $arParams['object_bedrooms_low'] : ''?>" maxlength="6" class="filter_block_field"/>
					</div>
					<div class="dash_separator"> - </div>
					<div class="filter_block_div">
						<input type="text" name="object_bedrooms_high" value="<?=$arParams['object_bedrooms_high'] > 0 ? $arParams['object_bedrooms_high'] : ''?>" maxlength="6" class="filter_block_field"/>
					</div>
				</div>
			</div>
			<div class="filter_block_ex ex" style="padding-top: 0px;">
				<span class="checkbox"><input id="swimpool" name="SwimmingPool" <?=$arParams['SwimmingPool'] == 1 ? ' checked="checked"' : ''?> value="1" class="CheckBox" type="checkbox"> <label for="swimpool"><?=$this->translate('бассейн')?></label></span>
				<span class="checkbox"><input id="protection" name="Security" <?=$arParams['Security'] == 1 ? ' checked="checked"' : ''?> value="1" class="CheckBox" type="checkbox"> <label for="protection"><?=$this->translate('охрана')?></label></span>
				<span class="checkbox"><input id="garage" name="Parking" <?=$arParams['Parking'] == 1 ? ' checked="checked"' : ''?> value="1" class="CheckBox" type="checkbox"> <label for="garage"><?=$this->translate('паркинг')?></label></span>
			</div>
			<div class="filter_block_ex ex" style="padding-top: 3px; width: 100px;">
				<span style="position: relative; float: left; width: 100%; height: 15px; margin: 2px 0px 0px 0px">ID</span>
				<div class="filter_block_div">
					<input maxlength="6" type="text" name="object_id" value="<?=$arParams['object_id'] > 0 ? $arParams['object_id'] : ''?>" class="filter_block_field"/>
				</div>
			</div>
		</div>
	</div>
</form>
